/**
  * Author: Mei
  * Date: 2020-12-13 13:45
  * Description: 
  *
  */
#include "../head.h"

using namespace std;

class A {
public:
    A() : array(new int[3]{1, 2, 3}) {
    }

    ~A() {
        cout << "destory_execute" << endl;
        if (nullptr != array) {
            delete[] array;
        }
    }

    A(const A &a) {
        //array = new int[3];
        //for(int i = 0; i < 3; ++i) {
        //    array[i] = a.array[i];
        //}
        array = a.array;
        cout << a.array << endl;
        std::cout << "Copy Construct" << endl;
    }

public:
    int *array{nullptr};
};

int main() {
    A a1;
    cout << "a1: " << a1.array[0] << endl;
    A a2(a1); //浅拷贝 同一块地址被析构两次
    cout << "a2: " << a2.array << endl; //为空

    return 0;
}